package com.aspose.cells;

class zawl extends zawk {
   private int f;
   private int g;
   private int h;
   private int i;
   private zfv j = new zfv();
   private zafu k;
   private zahr l;
   private boolean m = false;
   private int n = -1;
   private int o = -1;
   private int p = -1;
   private int q = -1;
   private zahl r;
   private zp s;

   public zawl(zaay var1, Cells var2, int var3, int var4, int var5, int var6) {
      super(var1, var2.h());
      this.k = var2.getRows().a;
      this.f = var3;
      this.h = var4;
      this.g = var5;
      this.i = var6;
   }

   public zahn b(zaay var1) {
      zawl var2 = new zawl(this.b, this.a.getCells(), this.f, this.h, this.g, this.i);
      var2.a(this);
      if (this.m) {
         var2.m = true;
         var2.n = this.n;
         var2.p = this.p;
         var2.o = this.o;
         var2.q = this.q;
      }

      return var2;
   }

   public int c() {
      return this.g - this.f + 1;
   }

   public int d() {
      return this.i - this.h + 1;
   }

   public int e() {
      return this.c() * this.d();
   }

   public boolean l() {
      return false;
   }

   public boolean m() {
      return false;
   }

   public boolean n() {
      return false;
   }

   public zagu a(int var1, int var2) {
      if (!this.m || var1 >= this.n && var1 <= this.o && var2 >= this.p && var2 <= this.q) {
         this.j.a = (short)(this.h + var2);
         zfv var3 = this.k.a(this.f + var1, this.j, 4);
         return (zagu)(var3 == null ? zzk.a : this.a(var3));
      } else {
         return zzk.a;
      }
   }

   public void f() {
      if (this.l != null) {
         this.l.b();
      } else if (this.m) {
         if (this.o < 0) {
            return;
         }

         this.l = this.k.a(this.f + this.n, this.f + this.o, false);
      } else {
         this.l = this.k.a(this.f, this.g, false);
         if (this.l == null) {
            this.m = true;
            return;
         }
      }

      if (this.l.hasNext()) {
         this.D();
         if (this.r != null) {
            return;
         }

         while(this.l.hasNext()) {
            this.D();
            if (this.r != null) {
               return;
            }
         }
      }

      this.l = null;
      this.m = true;
   }

   public boolean b(int var1, int var2) {
      if (this.m) {
         if (var1 > this.o) {
            return false;
         }

         if (var1 < this.n) {
            var1 = this.n;
            var2 = this.p;
         } else if (var2 > this.q) {
            ++var1;
            if (var1 > this.o) {
               return false;
            }

            var2 = this.p;
         }

         if (this.l == null) {
            this.l = this.k.a(this.f + this.n, this.f + this.o, false);
         }
      } else if (this.l == null) {
         this.l = this.k.a(this.f, this.g, false);
         if (this.l == null) {
            this.m = true;
            return false;
         }
      }

      if (this.s == null || this.s.h() != var1 + this.f) {
         this.l.a(var1 + this.f);
         if (!this.l.hasNext()) {
            return false;
         }

         this.s = this.l.e();
         this.r = this.s.b(var2 + this.h, this.m ? this.q + this.h : this.i, false);
      }

      if (this.r != null && this.E()) {
         return true;
      } else {
         do {
            if (!this.l.hasNext()) {
               return false;
            }

            this.D();
         } while(this.r == null || !this.E());

         return true;
      }
   }

   public boolean a(int var1) {
      int var2 = this.d();
      int var3 = var1 % var2;
      int var4 = var1 / var2;
      return this.b(var4, var3);
   }

   public boolean g() {
      if (this.m && this.n < 0) {
         return false;
      } else if (this.E()) {
         return true;
      } else {
         do {
            if (!this.l.hasNext()) {
               return false;
            }

            this.D();
         } while(this.r == null || !this.E());

         return true;
      }
   }

   private void D() {
      this.s = this.l.e();
      if (this.m) {
         this.r = this.s.b(this.p + this.h, this.q + this.h, false);
      } else {
         this.r = this.s.b(this.h, this.i, false);
      }

   }

   private boolean E() {
      int var1 = this.r.a();
      if (var1 < 0) {
         return false;
      } else if (this.e(var1)) {
         return true;
      } else {
         do {
            var1 = this.r.a();
            if (var1 < 0) {
               return false;
            }
         } while(!this.e(var1));

         return true;
      }
   }

   private boolean e(int var1) {
      if (this.s.h(var1) == 0) {
         return false;
      } else {
         this.c = this.s.a(var1, this.j, this.e);
         this.d = null;
         return true;
      }
   }

   public int i() {
      return this.s.h() - this.f;
   }

   public int j() {
      return this.c.a - this.h;
   }

   public int k() {
      return (this.s.h() - this.f) * (this.i - this.h + 1) + (this.c.a - this.h);
   }

   public zahn b(int var1) {
      var1 += this.f;
      zp var2 = this.k.a(var1);
      return (zahn)(var2 == null ? new zawz((zagu)null, 9, 1, this.d()) : new zawo(this.b, this.a, var2, this.h, this.i));
   }

   public zahn c(int var1) {
      return new zawn(this.b, this.a, var1 + this.h, this.f, this.g);
   }

   public boolean q() {
      return this.m;
   }

   public int r() {
      if (!this.m) {
         this.F();
      }

      return this.n;
   }

   public int s() {
      if (!this.m) {
         this.F();
      }

      return this.o;
   }

   public int t() {
      if (!this.m) {
         this.F();
      }

      return this.p;
   }

   public int u() {
      if (!this.m) {
         this.F();
      }

      return this.q;
   }

   public int v() {
      if (!this.m) {
         this.F();
      }

      return this.n * (this.i - this.h + 1) + this.p;
   }

   public int w() {
      if (!this.m) {
         this.F();
      }

      return this.o * (this.i - this.h + 1) + this.q;
   }

   private void F() {
      this.m = true;
      int[] var1 = new int[]{-1, -1};
      zahr var3 = this.k.a(this.f, this.g, false);
      zahl var4 = null;
      this.p = this.i + 1;

      label114:
      while(var3.hasNext()) {
         zp var6 = var3.e();
         if (var6.a() > 0 && var6.a(this.h, this.i, var1)) {
            int var2;
            int var5;
            if (this.p > this.h) {
               var4 = var6.a(this.h, var1[0], this.i, var1[1], false);

               do {
                  var2 = var4.a();
                  if (var2 < 0) {
                     continue label114;
                  }
               } while(var6.h(var2) == 0);

               this.o = var6.h();
               if (this.n < 0) {
                  this.n = this.o;
               }

               var5 = var6.a(var2);
               if (var5 < this.p) {
                  this.p = var5;
               }

               if (this.q < this.i) {
                  if (var2 < var1[1]) {
                     var4 = var6.a(var5, var2, this.i, var1[1], true);

                     do {
                        var2 = var4.a();
                        var5 = var6.a(var2);
                        if (var5 < this.q) {
                           continue label114;
                        }
                     } while(var6.h(var2) == 0);

                     this.q = var5;
                  } else if (this.q < var5) {
                     this.q = var5;
                  }
               }
            } else {
               if (this.q >= this.i) {
                  var4 = var6.a(this.h, var1[0], this.i, var1[1], false);

                  while(true) {
                     var2 = var4.a();
                     if (var2 < 0) {
                        break;
                     }

                     if (var6.h(var2) != 0) {
                        this.o = var6.h();
                        break;
                     }
                  }

                  if (var3.hasNext()) {
                     var3 = this.k.a(this.o + 1, this.g, true);
                     boolean var7 = false;

                     while(var3.hasNext()) {
                        var6 = var3.e();
                        var4 = var6.b(this.h, this.i, false);
                        if (var4 != null) {
                           while(true) {
                              var2 = var4.a();
                              if (var2 < 0) {
                                 break;
                              }

                              if (var6.h(var2) != 0) {
                                 this.o = var6.h();
                                 var7 = true;
                                 break;
                              }
                           }
                        }

                        if (var7) {
                           break label114;
                        }
                     }
                  }
                  break;
               }

               var4 = var6.a(this.h, var1[0], this.i, var1[1], true);

               do {
                  var2 = var4.a();
                  if (var2 < 0) {
                     continue label114;
                  }
               } while(var6.h(var2) == 0);

               this.o = var6.h();
               var5 = var6.a(var2);
               if (this.q < var5) {
                  this.q = var5;
               }
            }
         }
      }

      if (this.p > this.i) {
         this.p = -1;
      } else {
         this.p -= this.h;
         this.q -= this.h;
         this.n -= this.f;
         this.o -= this.f;
      }

   }
}
